package demo;

import java.util.Scanner;

/**
 * 银行业务的程序结构
 * 	银行帐户类BankAccount：
 * 	数据：余额、利率
 * 	操作：查询余额、存款、取款、查询利率、设置利率
 *
 * 	主类UseAccount：
 * 	main()方法，创建BankAccount类的对象，并完成相应操作
 */
public class UseAccount {
    public static void main(String[] args) {
        BankAccount ba = new BankAccount();
        System.out.println("初始余额为："+ba.getBalance()+",初始利率为："+ba.getRate());

        ba.setBalance(100d);
        ba.setRate(0.3d);
        Scanner sc = new Scanner(System.in);

        System.out.println("请存入一定金额：");
        double v = sc.nextDouble();
        ba.add(v);
        System.out.println("请设置利率：");
        double lv = sc.nextDouble();
        System.out.println("约为:"+ba.getBalance()+",利率为"+ba.getRate());
        System.out.println("请取款：");
        double h = sc.nextDouble();
        ba.sub(h);
        System.out.println("余额为:"+ba.getBalance());
    }
}

class BankAccount{
    /**
     * 余额
     */
    private double balance=0d;
    /**
     * 利率
     */
    private double rate=0d;

    public BankAccount(){

    }
    public BankAccount(double balance, double rate) {
        this.balance = balance;
        this.rate = rate;
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    public double getRate() {
        return rate;
    }

    public void setRate(double rate) {
        this.rate = rate;
    }

    public void  add(double n){
        this.balance +=n;
    }
    public void sub(double n){
        this.balance -=n;
    }
}
